﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class ShotManager
    {
        List<Shot> shotList;

        public int ShotCount
        {
            get { return shotList.Count; }
        }

        float delay;
        float nextShot;
        float lifeTime;
        Texture2D shotTexture;
        Animation[] animations;

        public ShotManager(float d, Texture2D t, Animation[] a, 
            float l)
        {
            this.delay = d;
            this.shotTexture = t;
            this.animations = a;
            this.lifeTime = l;
            shotList = new List<Shot>();
        }

        public void AddShot(GameTime gt, Vector2 p, 
            float v, Vector2 d, float r)
        {
            if (nextShot > (float)gt.TotalGameTime.TotalMilliseconds)
                return;
            nextShot += delay;
            shotList.Add(new Shot(p,Color.White,shotTexture,
                animations, (float)gt.TotalGameTime.TotalMilliseconds,
                v, d, r));
            
        }
        public void Update(GameTime gt)
        {
             if (shotList == null) return;
            for (int i = shotList.Count - 1; i >= 0; i--)
            {
                if (shotList[i] != null)
                {
                    shotList[i].Update(gt);
                    if (shotList[i].CreationTime + lifeTime <=
                        (float)gt.TotalGameTime.TotalMilliseconds)
                    {
                        shotList.RemoveAt(i);
                    }
                }
            }
        }



        public void Draw(SpriteBatch spriteBatch)
        {
            if (shotList == null) return;
            for (int i = shotList.Count - 1; i >= 0; i--)
            {

                if (shotList[i] != null)
                {
                    shotList[i].Draw(spriteBatch);
                }
            }
        }
    }
}
